package com.pj.compose

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.*
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import androidx.navigation.compose.rememberNavController
import com.pj.compose.NavRouters.APP_INDEX_PAGE
import com.pj.compose.NavRouters.OTHER_ROUTE_PATH
import com.pj.compose.NavRouters.WIDGET_ROUTE_PATH
import com.pj.compose.ui.page.main.AppPage
import com.pj.compose.ui.page.main.OtherPage
import com.pj.compose.ui.page.main.WidgetPage
import com.pj.compose.ui.page.other.ChangeThemePage
import com.pj.compose.ui.page.widget.*
import com.pj.compose.ui.page.widget.tabsegment.TabSegmentPage
import com.pj.compose.ui.page.widget.tabsegment.TabViewpagerPage

object NavRouters {
    const val WIDGET_ROUTE_PATH = "widget"
    const val OTHER_ROUTE_PATH = "other"
    const val APP_ROUTE_PATH = "app"
    const val MAIN_PAGE = "main"
    const val WIDGET_INDEX_PAGE = "WidgetIndex"
    const val WIDGET_BUTTON_PAGE = "Button"
    const val WIDGET_DIALOG_PAGE = "Dialog"
    const val FLOW_LAYOUT_PAGE = "Flow"
    const val WIDGET_TAB_SEGMENT_PAGE = "TabSegment"
    const val WIDGET_TAB_VIEWPAGE_PAGE = "TabViewPager"
    const val WIDGET_PROGRESS_BAR_PAGE = "ProgressBar"
    const val WIDGET_GROUP_LISTVIEW_PAGE = "GroupListView"
    const val WIDGET_TIP_DIALOG_PAGE = "TipDialog"
    const val WIDGET_RADIUS_IMAGE_VIEW_PAGE = "RadiusImageView"
    const val WIDGET_POPUPS_PAGE = "Popups"
    const val WIDGET_ECHART_PAGE = "EChart"
    const val WIDGET_MY_CANVAS_PAGE = "MyCanvas"
    const val WIDGET_SCROLL_TABLE_PAGE = "ScrollTablePage"
    const val BOTTOM_SHEET_PAGE = "BottomSheet"
    const val OTHER_INDEX_PAGE = "OtherIndex"
    const val CHANGE_THEME_PAGE = "ChangeTheme"
    const val APP_INDEX_PAGE = "APPIndex"
}


@Composable
fun NavGraph(
    navController: NavHostController = rememberNavController(),
    modifier: Modifier = Modifier
) {
    NavHost(
        navController = navController,
        startDestination = NavRouters.WIDGET_ROUTE_PATH,
        modifier = modifier
    ) {
        /*composable(route = NavRouters.MAIN_PAGE){
            MainPage(navController)
        }*/
        widgetGraph(navController)
        appGraph(navController)
        otherGraph(navController)
    }

}

/**
 * 界面
 */
fun NavGraphBuilder.widgetGraph(navController: NavController) {
    navigation(startDestination = NavRouters.WIDGET_INDEX_PAGE, route = WIDGET_ROUTE_PATH) {
        composable(route = NavRouters.WIDGET_INDEX_PAGE) {
            WidgetPage(navController)
        }

        composable(route = NavRouters.WIDGET_BUTTON_PAGE) {
            ButtonsPage(navController)
        }
        composable(route = NavRouters.WIDGET_DIALOG_PAGE) {
            DialogsPage(navController)
        }
        composable(route = NavRouters.FLOW_LAYOUT_PAGE) {
            FlowLayoutPage(navController)
        }
        composable(route = NavRouters.BOTTOM_SHEET_PAGE) {
            BottomSheetsPage(navController)
        }

        composable(route = NavRouters.WIDGET_TAB_SEGMENT_PAGE) {
            TabSegmentPage(navController)
        }

        composable(route = "${NavRouters.WIDGET_TAB_VIEWPAGE_PAGE}/{type}", arguments = listOf(
            navArgument("type") { type = NavType.IntType }
        )) {
            val type = it.arguments?.getInt("type",0)?:0
            TabViewpagerPage(navController,type)
        }

        composable(route = NavRouters.WIDGET_PROGRESS_BAR_PAGE) {
            ProgressBarPage(navController)
        }
        composable(route = NavRouters.WIDGET_GROUP_LISTVIEW_PAGE) {
            GroupListViewPage(navController)
        }
        composable(route = NavRouters.WIDGET_TIP_DIALOG_PAGE) {
            TipDialogPage(navController)
        }
        composable(route = NavRouters.WIDGET_RADIUS_IMAGE_VIEW_PAGE) {
            RadiusImageViewPage(navController)
        }
        composable(route = NavRouters.WIDGET_ECHART_PAGE) {
            EChartPage(navController)
        }
        composable(route = NavRouters.WIDGET_POPUPS_PAGE) {
            PopupsPage(navController)
        }
        composable(route = NavRouters.WIDGET_SCROLL_TABLE_PAGE) {
            ScrollTablePage(navController)
        }
        composable(route = NavRouters.WIDGET_MY_CANVAS_PAGE) {
            MyCanvasPage(navController)
        }
    }
}


/**
 * 仿写界面
 */
fun NavGraphBuilder.appGraph(navController: NavController) {
    navigation(startDestination = APP_INDEX_PAGE, route = NavRouters.APP_ROUTE_PATH) {
        composable(route = APP_INDEX_PAGE) {
            AppPage(navController = navController)
        }
    }
}

/**
 * 其它
 */
fun NavGraphBuilder.otherGraph(navController: NavController) {
    navigation(startDestination = NavRouters.OTHER_INDEX_PAGE, route = OTHER_ROUTE_PATH) {

        composable(route = NavRouters.OTHER_INDEX_PAGE) {
            OtherPage(navController = navController)
        }
        composable(route = NavRouters.CHANGE_THEME_PAGE) {
            ChangeThemePage(navController)
        }
    }
}

